package com.wnxy.eleba.controller;

import com.github.pagehelper.PageInfo;
import com.wnxy.eleba.entity.Dishes;
import com.wnxy.eleba.service.DishesService_zhuying;
import com.wnxy.eleba.service.DishesService_zhuying;
import com.wnxy.eleba.service.impl.DishesServiceImpl_zhuying;
import com.wnxy.eleba.utils.Result;
import com.wnxy.eleba.vo.DishesQueryParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品控制器
 */

@CrossOrigin
@RestController
@RequestMapping("/dishes")
public class DishesController_zhuying {

    private DishesService_zhuying DishesService;

    public final Logger logger = LoggerFactory.getLogger(DishesController_zhuying.class);

    @Autowired
    public void setDishesService(DishesService_zhuying DishesService) {
        this.DishesService = DishesService;
    }

    @PostMapping("/findAllDishes")
    public Result findAllDishes(){
        List<Dishes> list = DishesService.findAll();
        System.out.println(list);
        return Result.ok().data("list",list);

    }



    @PostMapping("/listDishesPageByCondition")
    public Result listDishesPageByCondition(@RequestBody DishesQueryParam DishesQueryParam){
        logger.warn(DishesQueryParam.toString());
        PageInfo<Dishes> pageInfo = DishesService.listDishesPageByCondition(DishesQueryParam);
//        System.out.println(pageInfo);
        return Result.ok().data("pageInfo",pageInfo);
        //return Result.ok().data("total",pageInfo.getTotal()).data("list",pageInfo.getList()).data("pageSize",pageInfo.getPageSize());
    }

    @GetMapping("/findDishesById")
    public Result findDishesById(@RequestParam("DishesId") Integer DishesId){
        logger.warn("DishesId:" + DishesId);
        Dishes Dishes = DishesService.findDishesById(DishesId);
        return Result.ok().data("Dishes",Dishes);
    }

    @PostMapping("/save")
    public Result saveDishes(@RequestBody Dishes Dishes){
        logger.warn("save Dishes:" + Dishes);
        boolean result = DishesService.saveDishes(Dishes);
        logger.warn("save result:" + result);
        System.out.println(Dishes);
        return Result.ok().success(result);
    }

    @PostMapping("/update")
    public Result updateDishes(@RequestBody Dishes Dishes){
        boolean result = DishesService.updateDishes(Dishes);
        return Result.ok().success(result);
    }

    @PostMapping("/delete")
    public Result deleteDishes(@RequestParam("ids")Integer... ids){
        boolean result = DishesService.deleteDishes(ids);
        System.out.println("2222");
        return Result.ok().success(result);
    }

    @GetMapping("/del")
    public Result delDishes(@RequestParam("id")Integer id){
        boolean result = DishesService.delDishes(id);
        System.out.println("2222");
        return Result.ok().success(result);
    }


    @GetMapping("/listDishesType")
    public Result listDishesType(){
        List<String> list = DishesService.listDishesType();
//        System.out.println("999999999");
//        System.out.println(list);

        return Result.ok().data("list",list);
    }

}
